package com.smartstores;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.smartstores.adapter.CustomListAdapter;

public class CarritoActivity extends ListActivity {

	private CustomListAdapter adapter;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		adapter = new CustomListAdapter(this,
				((SmartStoresApplication) getApplication()).getStore()
						.getCatalogo());

		setListAdapter(adapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater mi = getMenuInflater();
		mi.inflate(R.menu.menu, menu);

		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.ver_lista_compra:
			Intent i = new Intent(this, ListaComprasActivity.class);
			startActivity(i);
			break;
		case R.id.agregar_a_lista:
			((SmartStoresApplication) getApplication()).getStore()
					.agregarListadoCompras(adapter.getItemsChecked());
			adapter.uncheckAll();
			break;
		}

		return true;
	}
}